import db from '../db/index.js'
export function getlacssroom(req, res) {
    const { pagesize, pagenum } = req.body
    const page = (pagenum - 1) * pagesize
    const sql = `select roomid,name,region,type,postion from classroom limit ${pagesize} offset ${page}`
    db.query(sql, (err, data) => {
        if (err) return res.dbno(err)
        const classroom = data
        const sql2 = 'select count(*) as total from classroom'
        db.query(sql2, (err, data) => {
            if (err) return res.dbno(err)
            const total = data[0].total
            res.send({ status: 200, classroom, total })
        })
    })
}
export function seachclassroom(req, res) {
    const { pagesize, pagenum ,condition, val} = req.body
    const page = (pagenum - 1) * pagesize
    const sql = `select roomid,name,region,type,postion from classroom where ${condition}=? limit ${pagesize} offset ${page}`
    db.query(sql,val, (err, data) => {
        if (err) return res.dbno(err)
        const classroom = data
        const sql2 = `select count(*) as total from classroom where ${condition}=?`
        db.query(sql2, val,(err, data) => {
            if (err) return res.dbno(err)
            const total = data[0].total
            res.send({ status: 200, classroom, total })
        })
    })
}